//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tools\fn_createVehicle.sqf"
#include <tmf_constants.h>
#include <tmf_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;
 //[type, position, markers, placement, special]
private ["_object","_objects","_grp","_pos","_dist","_markers","_type","_init","_instance_id"];
DEFAULT_PARAM(_instance_id,0,TMF_SERVER_INSTANCE_ID);
DEFAULT_PARAM(_type,1,"");
DEFAULT_PARAM(_pos,2,ARR_3(0,0,0));
DEFAULT_PARAM(_markers,3,[]);
DEFAULT_PARAM(_dist,4,0);
DEFAULT_PARAM(_special,5,"");
DEFAULT_PARAM(_init,6,[]);

if (_instance_id == "") then { _instance_id = TMF_SERVER_INSTANCE_ID; };

if (!IS_STRING(_init)) then {
	_init = "";
};

_new_pos = [];
if (_dist > 0) then {
	_new_pos = _pos findEmptyPosition[ 1 , _dist , _type];
	if (count _new_pos > 0) then { _pos = _new_pos; };
};
_object = objNull;
TRACE_2("CreateVehicle",_type,ARR_3(_pos, _special, _init));
_object = createVehicle [_type, _pos, _markers, 0, _special];
[_object,_instance_id] call FFUNC(setInstanceID);
[QGVAR(s_store_vehicle),[_object,_instance_id],THIS_FILE] call FFUNC(callEvent);

TRACE_1("End",ARR_3(_object,typeof _object,getPos _object));
TMFPROFILERSTOP;
_object